$(function () {
    $.validator.addMethod("checkeUtelphone", function (value, element, params) {

        return /^[1]\d{10}$/.test(value);
    })
    $("form").validate({
        //rules 规则
        //messages 消息
        //submitHandler 提交
        rules: {
            utelphone: {
                required: true,
                rangelength: [11, 11],
                checkeUtelphone: true
            },
            upwd: {
                required: true,
                rangelength: [6, 18],
            },
            upwd2: {
                equalTo: "#upwd"
            }
        },
        messages: {
            utelphone: {
                required: "手机号必填",
                rangelength: "手机号必须是{0}位",
                checkeUtelphone: "手机号不合法"

            },
            upwd: {
                required: "密码必填",
                rangelength: "密码长度必须是{0}-{1}位",
            },
            upwd2: {
                equalTo: "2次密码不一致"
            }
        },
        submitHandler:function () {
            $.ajax({
              url:"http:./../server/registerServer.php",
                data:$("form").serialize(),
                type:"post",
                dataType:"json"
            }).then(function (res) {
                if (res.status == 1) {
                    // layer.confirm("文子提示",{},yes,no)
                    layer.confirm('是否需要立即登录？',
                        {
                            icon: 1,
                            title: res.msg,//提示
                            skin: 'layui-layer-molv',//皮肤
                            btn: ['是', '否'], //按钮列表
                            // time: 2000 // 2000毫秒自动关闭
                        }, function (index) {
                            location = "./denglu.html";
                        });

                } else {

                    layer.alert(res.msg, {
                        icon: 2,
                        skin: 'layui-layer-molv'
                    })
                }
            })

            return false;
        }
    })
    $.idcode.setCode();
    $("form").on("submit", function (e) {
        var IsBy = $.idcode.validateCode();//调用返回值，返回为true或false
        if (IsBy) {
            $.ajax({
                url: "http:./../server/registerServer.php",
                data: $("form").serialize(),
                async: true,
                type: "post",
                dataType: "json"
            })
        } else {
            layer.msg("验证码有误");
        }
        return false
    })
})